#include "Define.h"

STDAPI InterfaceTableQueryInterface(
    void* pThis, 
    const INTERFACE_ENTRY* pTable, 
    REFIID riid, 
    void** ppv
)
{
    HRESULT hResult = S_OK;

    if (!ppv)
        return S_FALSE;

    *ppv = nullptr;

    if (InlineIsEqualGUID(riid, IID_IUnknown))
    {
        *ppv = pThis;
    }
    else
    {
        for (unsigned int i = 0; pTable[i].iid != GUID_NULL; i++)
        {
            if (InlineIsEqualGUID(riid, pTable[i].iid))
            {
                *ppv = (char*)pThis + pTable[i].Offset;
                break;
            }
        }

        if (*ppv == nullptr)
            hResult = S_FALSE;
    }

    return hResult;
}